import axios from './ajax'
import { ResDataType, SearchOption } from './types'

export async function getQuestionService(id: string): Promise<ResDataType> {
  const url = `/api/question/${id}`

  return (await axios.get(url)) as ResDataType
}

export async function createQuestionService(): Promise<ResDataType> {
  const url = `/api/question`

  return (await axios.post(url)) as ResDataType
}

export async function getQuestionListService(opt: Partial<SearchOption> = {}): Promise<ResDataType> {
  const url = '/api/question'

  return (await axios.get(url, { params: opt })) as ResDataType
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function updateQuestionService(id: string, data: { [key: string]: any }): Promise<ResDataType> {
  const url = `/api/question/${id}`

  return (await axios.patch(url, data)) as ResDataType
}

export async function duplicateQuestionService(id: string): Promise<ResDataType> {
  const url = `/api/question/duplicate/${id}`

  return (await axios.post(url)) as ResDataType
}

export async function deleteQuestionsService(ids: string[]): Promise<ResDataType> {
  const url = `/api/question`

  return (await axios.delete(url, { data: ids })) as ResDataType
}
